import React, {ChangeEventHandler} from 'react';
import {Form, Input} from "antd";
import BaseEntity from "../../type/entity";

interface IProps<T> {
    name: keyof T,
    lastName?: keyof T,
    label: string,
    placeholder?: string,
    required?: boolean,
    disabled?: boolean
    suffix?: React.ReactNode
    onChange?: ChangeEventHandler<HTMLInputElement> | undefined
}
/**
 * 用户输入文本信息的表单
 * @param props 属性
 */
const InputText = <T extends BaseEntity>(props: IProps<T>) => {
    const { name, label } = props;
    // TODO: 这里的name属性需要转换为any类型,name本身必定是T的属性名,但是不知道为什么会报错
    return (
        <Form.Item<T>
            name={name as any}
            label={label}
            required={props.required}
            rules={[{required: props.required, message: `${label}不能为空!` }]}
        >
            <Input onChange={props.onChange} disabled={props.disabled} placeholder={props.placeholder ?? `请输入${label}`} suffix={props.suffix}/>
        </Form.Item>
    );
};

export default InputText;